export default function(refContainer){
    return { 
        mounted(){
            this.$refs[refContainer].addEventListener('scroll', this.handleScroll);
            this.$eventBus.$on('mainScrollTop', this.toTop)
        },
        beforeDestroy(){ 
            this.$refs[refContainer].removeEventListener('scroll', this.handleScroll);
            this.$eventBus.$emit('mainScroll');
        },
        destroyed(){
            this.$eventBus.$off('mainScrollTop', this.toTop)
        },
        methods: {
            handleScroll(){
                this.$eventBus.$emit('mainScroll', this.$refs[refContainer]);
            },
            toTop(scroll){
                this.$refs[refContainer].scrollTop = scroll;
            }
        }
    }
}